#include "treewidget.h"
#include <QMouseEvent>
#include <QMessageBox>

#include "formmain.h"


TreeWidget::TreeWidget(QWidget *parent) : QTreeWidget(parent) {
}

void TreeWidget::mousePressEvent(QMouseEvent *event) {
	if (itemAt(event->pos())) {
		if (event->button() == Qt::RightButton)
			emit itemMouseClicked(itemAt(event->pos()), RIGHT);
		else if (event->button() == Qt::LeftButton)
			emit itemMouseClicked(itemAt(event->pos()), LEFT);
	}
	QTreeWidget::mousePressEvent(event);
	emit mousePressed(event);
}

void TreeWidget::keyPressEvent(QKeyEvent *event) {
    emit keyPressed(event);
	QTreeWidget::keyPressEvent(event);
}

QString TreeWidget::currentTopLevelText(int column)
{
	QString ret;
	QTreeWidgetItem *current = currentItem();

	if (current) {
		while (current->parent()) {
			current = current->parent();
		}
		ret = current->text(column);
	}

	return ret;
}
